#/bin/bash
url="http://47.96.191.61:9000/#!/1/docker/stacks/xdapi?id=53&type=2&external=false"
str=$(cat docker.sh | tail -n 1)
str=${str#*:} # 取”:“后的内容
array=(${str//./ }) # 以“.”分割
# v1.v2.v3
declare -i v1=${array[0]}
declare -i v2=${array[1]}
declare -i v3=${array[2]}

echo "#/bin/bash
swag init
docker build -t registry.cn-hangzhou.aliyuncs.com/inpm/xd_work_api:$v1.$v2.$[v3+1] ./
docker push registry.cn-hangzhou.aliyuncs.com/inpm/xd_work_api:$v1.$v2.$[v3+1]" > docker.sh

echo "package main

import (
	\"singo/conf\"
	_ \"singo/docs\"
	\"singo/server\"
)

// @title xd-work swagger
// @version $v1.$v2.$[v3+1]
// @description xd-work service

// @contact.name 陈宇汐文
// @contact.email inpm.cy@gmail.com

// @host xd.inpm.top

func main() {
	// 从配置文件读取配置
	conf.Init()

	// 装载路由
	r := server.NewRouter()
	r.Run(\":3001\")
}
" > main.go

echo "version: '2'

services:
  api:
    image: registry.cn-hangzhou.aliyuncs.com/inpm/xd_work_api:$v1.$v2.$[v3+1]
    container_name: xd_work_api
    restart: always
    environment:
      MYSQL_DSN: root:root123456@tcp(172.26.120.202:3306)/db1?charset=utf8mb4,utf8&parseTime=True&loc=Local
      REDIS_ADDR: 172.26.120.202:6379
      REDIS_DB: 0
      SESSION_SECRET: rBaXcd1PPrC1
      GIN_MODE: release
      LOG_LEVEL: debug
      OSS_END_POINT: inpm-images.oss-cn-shenzhen.aliyuncs.com
      OSS_ACCESS_KEY_ID: LTAI4GCi4Qc3qTAuYc2txxFt
      OSS_ACCESS_KEY_SECRET: G9FfizN4Aj2iaz9WPypIK0o7Pkvtjf
    ports:
      - 3001:3001
    depends_on:
      - redis
      - mysql
  mysql:
    container_name: mysql
    image: mysql:8.0.21
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root123456
      MYSQL_DATABASE: db1
    volumes:
      - mysql_data:/mysql_data
    ports:
      - 3306:3306
  redis:
    container_name: redis
    image: redis:6.0.6
    restart: always
    volumes:
      - redis_data:/redis_data
    ports:
      - 6379:6379" > docker-compose.yml

sh docker.sh

echo "package main

import (
	\"singo/conf\"
	_ \"singo/docs\"
	\"singo/server\"
)

// @title xd-work swagger
// @version $v1.$v2.$v3
// @description xd-work service

// @contact.name 陈宇汐文
// @contact.email inpm.cy@gmail.com

// @host localhost:3001

func main() {
	// 从配置文件读取配置
	conf.Init()

	// 装载路由
	r := server.NewRouter()
	r.Run(\":3001\")
}
" > main.go

echo "请到这里修改版本号：$url"
echo "api当前版本号是：$v1.$v2.$[v3+1]"